import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
/**
 * 
 * @author "Cunxin Jia"
 *
 */

public class Foreground {
	private Set<Literal> posSet;
	private List<Literal> posSetRemained;
	private Set<Literal> negSet;
	
	public Foreground(Set<Literal> posSet, Set<Literal> negSet) {
		this.posSet = posSet;
		this.negSet = negSet;
	}
	
	
	public Set<Literal> getPosSet() {
		return posSet;
	}
	
	public Set<Literal> getRemainedPosSet() {
		Set<Literal> remained = new HashSet<Literal>();
		remained.addAll(posSetRemained);
		return remained;
	}
	
	public void removeCoveredPos(Set<Literal> coveredSet) {
		posSet.removeAll(coveredSet);
		posSetRemained.removeAll(coveredSet);
	}
	
	public Literal randomSelectPos() {
		if(posSetRemained == null) {
			posSetRemained = new ArrayList<Literal>();
			posSetRemained.addAll(posSet);
		}
		if(posSetRemained.size() == 0) {
			return null;
		}
		Random rand = new Random();
		int selectedIndex = Math.abs(rand.nextInt()) % posSetRemained.size();
		Literal selected = posSetRemained.get(selectedIndex);
		posSetRemained.remove(selectedIndex);
		return selected;
	}
	
}
